package pl.elka.simulator.core.configurationCommand;

import java.util.HashMap;
import java.util.Map;

public class ConfigurationCommandFactory {
	private Map<ConfigurationCommandType, ICommandParamConstructor> constructors = new HashMap<ConfigurationCommandType, ICommandParamConstructor>();
	private Map<ConfigurationCommandType,IConfigurationCommand> commands = new HashMap<ConfigurationCommandType, IConfigurationCommand>();
	private static ConfigurationCommandFactory instance = new ConfigurationCommandFactory();
	
	public void registerCommandPattern(IConfigurationCommand cmd, ICommandParamConstructor constructor){
		constructors.put(cmd.getType(), constructor);
		commands.put(cmd.getType(), cmd);
	}
	
	public ICommandParamConstructor getConstructorByType(ConfigurationCommandType type){
		return constructors.get(type).newInstance();
	}
	public IConfigurationCommand getCommandByType(ConfigurationCommandType type){
		return commands.get(type).newInstance();
	}
	
	private ConfigurationCommandFactory(){}
	public static ConfigurationCommandFactory getInstance(){
		return instance;
	}
}
